#include "book.h"
#include "book_info.h"
#include "tools.h"

Book::Book(void) {}
// 构造函数
Book::Book(const char* name,const char* author,unsigned int id,const char* type,struct tm& intime,unsigned int amout,
	unsigned int total,double score,unsigned int sco_num,unsigned int recom,const char* syn,bool isShelf,
		unsigned int numCom,unsigned int numRecord) : m_name(name),m_author(author),m_id(id),m_type(type),
			m_intime(intime),m_amout(amout),m_total(total),m_score(score),m_sco_num(sco_num),m_recom(recom),
				m_syn(syn),m_isShelf(isShelf),m_numCom(numCom),m_numRecord(numRecord) {}

// 删除评论
bool Book::delComment(unsigned int com_id)
{
	vector<Comment>::iterator it;
	for(it = m_vecCom.begin(); it != m_vecCom.end(); it++)
	{
		Comment comment = *it;
		if(com_id == comment.m_id)
		{
			m_vecCom.erase(it);
			return true;
		}
	}
	return false;
}

// 添加借书记录
void Book::addRecord(Record& record)
{
	m_record.push_back(record);
}

// 添加评论
void Book::addComment(Comment& com)
{
	m_vecCom.push_back(com);
}

// 获取借书记录 并返回记录指针
Record* Book::getRecord(unsigned int com_id)
{
	if(com_id > m_record.size() || 0 > com_id) return NULL;
	for(unsigned int i=0;i<m_record.size();i++)
	{
		if(com_id == m_record.at(i).m_id)
		{
			return &m_record.at(i);
		}
	}
	return NULL;
}

